package emby.stmt;

import emby.expr.Expression;
import emby.expr.Variable;
import emby.lang.EmbyFunction;
import emby.lang.Scope;
import emby.writer.IEmbyCodifier;

public class CompoundAssignment extends Assignment {
	private static final long serialVersionUID = -7572192079982316630L;

	Variable v;
	EmbyFunction operator;
	Expression val;
	public CompoundAssignment(Variable var, EmbyFunction operator, Expression val) {
		super(var, val);
		v = var;
		this.operator = operator;
		this.val = val;
	}
	
	@Override
	public Object eval(Scope s) {
		Object expr = value.eval(s);
		Object varValue = s.getVar(this.getLine(), v.getName());
		Object newVarValue = operator.execute(this.getLine(), s, varValue, expr);
		v.setVar(s, newVarValue);
		return null;
	}

	public void codify(IEmbyCodifier ec){
		ec.compassign(v, operator, val);
	}
}
